// /**
//  * Copyright © 2016 Magento. All rights reserved.
//  * See COPYING.txt for license details.
//  */

//
//  UI -> Data Grid
//  _____________________________________________

//
//  Components
//  ---------------------------------------------

@import 'data-grid/_data-grid-static.less';
@import 'data-grid/_data-grid-header.less';

//

.admin__data-grid-outer-wrap {
    min-height: @data-grid-spinner__size + @indent__base * 2;
    position: relative; // Used to keep spinner inside
}

.admin__data-grid-wrap {
    margin-bottom: 2rem;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 1rem;
    padding-top: @data-grid-header-row__indent;
}

.admin__data-grid-loading-mask {
    background: rgba(255, 255, 255, .5);
    bottom: 0;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    z-index: @data-grid-overlay__z-index;

    .spinner {
        font-size: @data-grid-spinner__size;
        left: 50%;
        margin-left: -(@data-grid-spinner__size / 2);
        margin-top: -(@data-grid-spinner__size / 2);
        position: absolute;
        top: 50%;

        .ie9 & {
            background: url('@{baseDir}images/loader-2.gif') 50% 50% no-repeat;
            bottom: 0;
            height: 149px;
            left: 0;
            margin: auto;
            position: absolute;
            right: 0;
            top: 0;
            width: 218px;
        }
    }
}

.data-grid-cell-content {
    display: inline-block;
    overflow: hidden;
    width: 100%;
}

body._in-resize {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: col-resize;

    .data-grid-th,
    .data-grid-th._sortable,
    .data-grid-th._draggable {
        cursor: col-resize !important;
    }

    * {
        cursor: col-resize !important;
    }
}

._layout-fixed {
    table-layout: fixed;
}

.data-grid {
    border: none;
    font-size: @data-grid__font-size;
    margin-bottom: 0;
    width: 100%;

    &:not(._dragging-copy) {
        ._odd-row {
            td {
                &._dragging {
                    background-color: @data-grid-td__even__dragging__background-color;
                }
            }
        }

        ._dragging {
            background-color: @data-grid-td__odd__dragging__background-color;
            color: fade(@table__color, @data-grid-td__dragging__opacity);

            a {
                color: fade(@link__color, @data-grid-td__dragging__opacity);

                &:hover {
                    color: fade(@link__hover__color, @data-grid-td__dragging__opacity);
                }
            }
        }
    }

    &._dragged {
        outline: 1px solid @data-grid-dragging-copy__outline-color;
    }

    thead {
        background-color: transparent;
    }

    tfoot {
        th {
            padding: @data-grid-cell__padding-vertical @data-grid-cell__padding-horizontal;
        }
    }

    tr {
        &._odd-row {
            td {
                background-color: @data-grid-td__even__background-color;

                &._update-status-active {
                    background: @data-grid-td__odd__update__active__background-color;
                }

                &._update-status-upcoming {
                    background: @data-grid-td__odd__update__upcoming__background-color;
                }
            }
        }

        &:hover {
            td {
                &._update-status-active,
                &._update-status-upcoming {
                    background-color: @data-grid-tr__hover__background-color;
                }
            }
        }

        &.data-grid-tr-no-data {
            td {
                font-size: @data-grid__no-records__font-size;
                padding: @data-grid__no-records__padding;
                text-align: center;
            }

            &:hover {
                td {
                    background-color: @data-grid-td__odd__background-color;
                    cursor: default;
                }
            }
        }
    }

    tr {
        &:active {
            td {
                background-color: @data-grid-tr__active__background-color;
            }
        }

        &:hover {
            td {
                background-color: @data-grid-tr__hover__background-color;
            }
        }

        &._dragged {
            td {
                background: @data-grid-td__dragging__background-color;
            }
        }

        &._dragover-top {
            td {
                box-shadow: inset 0 @data-grid-horizontal-dragover-mark__width 0 0 @data-grid-horizontal-dragover-mark__color;
            }
        }

        &._dragover-bottom {
            td {
                box-shadow: inset 0 -@data-grid-horizontal-dragover-mark__width 0 0 @data-grid-horizontal-dragover-mark__color;
            }
        }

        &:not(.data-grid-editable-row) {
            &:last-child {
                td {
                    border-bottom: @data-grid-cell__border-width @data-grid-td__border-outer-style @data-grid-td__border-color;
                }
            }
        }

        &._clickable,
        ._clickable {
            cursor: pointer;
        }

        &._disabled {
            pointer-events: none;
        }
    }

    th,
    td {
        font-size: @data-grid__font-size; // ToDo UI: Rewrite old styles. Should be deleted afterwards
        line-height: @line-height__base;
        transition: @smooth__background-color;
        vertical-align: top;

        &._resizing {
            border-left: 1px solid @color-blue-pure;
            border-right: 1px solid @color-blue-pure;
        }

        &._hidden {
            display: none;
        }

        &._fit {
            width: 1%;
        }
    }

    td {
        background-color: @data-grid-td__odd__background-color;
        border-left: @data-grid-cell__border-width @data-grid-td__border-inner-style @data-grid-td__border-color;
        border-right: @data-grid-cell__border-width @data-grid-td__border-inner-style @data-grid-td__border-color;
        color: @table__color;
        padding: @data-grid-cell__padding-vertical @data-grid-cell__padding-horizontal;

        &:first-child {
            border-left-style: @data-grid-td__border-outer-style;
        }

        &:last-child {
            border-right-style: @data-grid-td__border-outer-style;
        }

        //  Action select data grid styles (can be action-select-secondary in future)
        .action-select-wrap {
            position: static;
        }

        .action-select {
            background-color: transparent;
            border: none;
            font-size: @data-grid__font-size;
            position: relative;
            .link-pattern();
            padding: 0 3rem 0 0;

            &:hover {
                &:after {
                    border-color: @link__hover__color transparent transparent transparent;
                }
            }

            &:after {
                border-color: @link__color transparent transparent transparent;
                margin: .6rem 0 0 .7rem;
                right: auto;
                top: auto;
            }

            &:before {
                display: none;
            }
        }

        .action-menu {
            left: auto;
            min-width: 10rem;
            right: 0;
            text-align: left;
            top: auto;
            z-index: 1;
        }

        &._update-status-active {
            background: @data-grid-td__update__active__background-color;
        }

        &._update-status-upcoming {
            background: @data-grid-td__update__upcoming__background-color;
        }
    }

    th {
        background-color: @data-grid-th__background-color;
        border: @data-grid-cell__border-width @data-grid-th__border-style @data-grid-th__border-color;
        border-left-color: transparent;
        color: @data-grid-th__color;
        font-weight: @font-weight__semibold;
        padding: 0;
        text-align: left;

        &:first-child {
            border-left-color: @data-grid-th__border-color;
        }

        &._dragover-left {
            box-shadow: inset 3px 0 0 0 @color-white;
            z-index: 2;
        }

        &._dragover-right {
            box-shadow: inset -3px 0 0 0 @color-white;
        }
    }

    .shadow-div {
        cursor: col-resize;
        height: 100%;
        margin-right: -5px;
        position: absolute;
        right: 0;
        top: 0;
        width: 10px;
    }

    .data-grid-th {
        background-clip: padding-box; // Fix for border overlay in Firefox
        color: @data-grid-th__color;
        padding: @data-grid-th__padding-vertical @data-grid-th__padding-horizontal;
        position: relative;
        vertical-align: middle;

        &._resize-visible {
            .shadow-div {
                cursor: auto;
                display: none;
            }
        }

        &._draggable {
            cursor: -webkit-grab;
            cursor:    -moz-grab;
            cursor:         grab;
        }

        &._sortable {
            cursor: pointer;
            transition: @smooth__background-color;
            z-index: 1;

            &:focus,
            &:hover {
                background-color: @data-grid-th__hover__background-color;
            }

            &:active {
                padding-bottom: @data-grid-th__padding-vertical - .1rem;
                padding-top: @data-grid-th__padding-vertical + .1rem;
            }
        }

        //  Required column
        &.required {
            > span {
                &:after {
                    color: @data-grid-th-marker__required__color;
                    content: '*';
                    margin-left: .3rem;
                }
            }
        }
    }

    .data-grid-checkbox-cell {
        padding: 0;
        vertical-align: top;
        width: @control-checkbox-radio__size + @data-grid-checkbox-cell-inner__padding-horizontal * 2;

        &:hover {
            cursor: default;
        }
    }

    .data-grid-thumbnail-cell {
        text-align: center;
        width: 7rem;

        img {
            border: 1px solid @data-grid-td__border-color;
            width: 5rem;
        }
    }

    .data-grid-multicheck-cell {
        padding: @data-grid-th__padding-horizontal @data-grid-th__padding-vertical @data-grid-th__padding-horizontal - .1rem;
        text-align: center;
        vertical-align: middle;
    }

    .data-grid-onoff-cell {
        text-align: center;
        width: 12rem;
    }

    .data-grid-actions-cell {
        padding-left: @data-grid-cell__padding-horizontal * 2;
        padding-right: @data-grid-cell__padding-horizontal * 2;
        text-align: center;
        width: 1%;
    }

    //  Draggable columns
    &._hidden {
        display: none;
    }

    &._dragging-copy {
        box-shadow: @component__box-shadow__base;
        left: 0;
        opacity: .95;
        position: fixed;
        top: 0;
        z-index: @data-grid-dargging-copy__z-index;

        .data-grid-th {
            border: @data-grid-dragging-copy__border;
            border-bottom: none;
        }

        .data-grid-th,
        .data-grid-th._sortable {
            cursor: -webkit-grabbing;
            cursor:    -moz-grabbing;
            cursor:         grabbing;
        }

        tr {
            &:last-child {
                td {
                    border-bottom: @data-grid-dragging-copy__border;
                }
            }
        }

        td {
            border-left: @data-grid-dragging-copy__border;
            border-right: @data-grid-dragging-copy__border;
        }

        &._in-edit {
            .data-grid-editable-row {
                &.data-grid-bulk-edit-panel {
                    &:hover {
                        td {
                            background-color: fade(@data-grid-bulk-edit-panel__background-color, @data-grid-td__dragging__opacity);
                        }
                    }

                    td {
                        background-color: fade(@data-grid-bulk-edit-panel__background-color, @data-grid-td__dragging__opacity);

                        &:before {
                            background-color: fade(@data-grid-bulk-edit-panel__background-color, @data-grid-td__dragging__opacity);
                        }
                    }
                }

                &:hover {
                    td {
                        background-color: fade(@data-grid-td__odd__background-color, @data-grid-td__dragging__opacity);
                    }
                }

                td {
                    background-color: fade(@data-grid-td__odd__background-color, @data-grid-td__dragging__opacity);

                    &:before,
                    &:after {
                        left: 0;
                        right: 0;
                    }

                    &:before {
                        background-color: fade(@data-grid-td__odd__background-color, @data-grid-td__dragging__opacity);
                    }

                    &:only-child {
                        border-left: @data-grid-dragging-copy__border;
                        border-right: @data-grid-dragging-copy__border;
                        left: 0; // Cancel border overlay fix in Firefox
                    }
                }

                .admin__control-text,
                .admin__control-select {
                    opacity: @disabled__opacity;
                }
            }
        }
    }

    .data-grid-controls-row td {
        padding-top: @data-grid-cell__padding-vertical + @field-control__padding-top;

        &.data-grid-checkbox-cell {
            padding-top: @field-control__padding-top;
        }

        button,
        [class*='admin__control-'] {
            margin-top: -@field-control__padding-top - @field-control__border-width - .1rem;
        }
    }

    //  Editable row
    &._in-edit {
        tr {
            &:hover {
                td {
                    background-color: @data-grid-td__odd__edit__background-color;
                }
            }
        }

        ._odd-row {
            &.data-grid-editable-row {
                &:hover {
                    td {
                        background-color: @data-grid-td__odd__background-color;
                    }
                }

                td {
                    background-color: @data-grid-td__odd__background-color;
                }
            }

            &:hover {
                td {
                    background-color: @data-grid-td__even__edit__background-color;
                }
            }

            td {
                background-color: @data-grid-td__even__edit__background-color;
            }
        }

        .data-grid-editable-row-actions {
            &:hover {
                td {
                    background-color: @data-grid-td__odd__background-color;
                }
            }

            td {
                background-color: @data-grid-td__odd__background-color;
            }
        }

        td {
            background-color: @data-grid-td__odd__edit__background-color;
            pointer-events: none;
        }

        .data-grid-checkbox-cell {
            pointer-events: auto;
        }

        .data-grid-editable-row {
            border: @data-grid-cell__border-width @data-grid-td__border-outer-style @data-grid-editable-cell__border-color;
            border-bottom-color: @color-gray76;

            &:hover {
                td {
                    background-color: @data-grid-td__odd__background-color;
                }
            }

            td {
                background-color: @data-grid-td__odd__background-color;
                border-bottom-color: @data-grid-td__odd__background-color;
                border-left-style: hidden;
                border-right-style: hidden;
                border-top-color: @data-grid-td__odd__background-color;
                pointer-events: auto;
                vertical-align: middle;

                &:first-child {
                    border-left-color: @data-grid-editable-cell__border-color;
                    border-left-style: solid;

                    &:after {
                        left: 0;
                    }

                    &:before {
                        left: 0;
                    }
                }

                &:last-child {
                    border-right-color: @data-grid-editable-cell__border-color;
                    border-right-style: solid;
                    left: -(@data-grid-cell__border-width); // Fix bug with border in FF

                    &:after {
                        right: 0;
                    }

                    &:before {
                        right: 0;
                    }
                }
            }

            .admin__control-text,
            .admin__control-select {
                width: 100%;
            }
        }

        .data-grid-bulk-edit-panel {
            td {
                vertical-align: bottom;
            }
        }
    }

    .data-grid-editable-row {
        td {
            border-left-color: @data-grid-td__odd__background-color;
            border-left-style: solid;
            position: relative;
            z-index: 1;

            &:after {
                bottom: 0;
                box-shadow: 0 5px @component__shadow-size__base rgba(0, 0, 0, .25);
                content: '';
                height: @data-grid-cell__padding-vertical - .1rem;
                left: 0;
                margin-top: -(@data-grid-cell__padding-vertical);
                position: absolute;
                right: 0;
            }

            &:before {
                background-color: @data-grid-td__odd__background-color;
                bottom: 0;
                content: '';
                height: @data-grid-cell__padding-vertical;
                left: -@component__shadow-size__base * 2;
                position: absolute;
                right: -@component__shadow-size__base * 2;
                z-index: 1;
            }
        }

        &.data-grid-editable-row-actions {
            &:hover {
                td {
                    background-color: @data-grid-td__odd__background-color;
                }
            }

            td {
                background-color: @data-grid-td__odd__background-color;

                &:first-child {
                    border-left-color: @data-grid-td__odd__background-color;
                    border-right-color: @data-grid-td__odd__background-color;
                }

                &:last-child {
                    left: 0; // Fix bug with border in FF
                }
            }
        }

        &.data-grid-bulk-edit-panel {
            td {
                background-color: @data-grid-bulk-edit-panel__background-color;

                &:before {
                    background-color: @data-grid-bulk-edit-panel__background-color;
                }
            }

            &:hover {
                td {
                    background-color: @data-grid-bulk-edit-panel__background-color;
                }
            }
        }
    }

    .data-grid-editable-row-actions {
        left: 50%;
        margin-left: -(@data-grid-editable-row-actions__width / 2);
        margin-top: -2px;
        position: absolute;
        text-align: center;

        td {
            width: @data-grid-editable-row-actions__width;
        }

        [class*='action-'] {
            min-width: 9rem;
        }
    }

    //  Draggable row
    .data-grid-draggable-row-cell {
        width: 1%;

        .draggable-handle {
            &:extend(.abs-draggable-handle all);
            padding: 0;
        }
    }

    .action-delete {
        &:extend(.abs-action-button-as-link all);
    }
}

//  Ascend & Descend sort marker
.data-grid-th {
    &._sortable {
        &._ascend,
        &._descend {
            padding-right: @data-grid-th__padding-horizontal * 2 + @data-grid-th-marker__width;

            &:before {
                margin-top: -1em;
                position: absolute;
                right: @data-grid-th__padding-horizontal;
                top: 50%;
            }
        }

        &._ascend {
            &:before {
                content: '\2193';
            }
        }

        &._descend {
            &:before {
                content: '\2191';
            }
        }
    }
}

//  Checkbox actions column
.data-grid-checkbox-cell-inner {
    display: block;
    padding: @data-grid-checkbox-cell-inner__padding-top @data-grid-checkbox-cell-inner__padding-horizontal .9rem;
    text-align: right;

    &:hover {
        cursor: pointer;
    }
}

//  State actions column
.data-grid-state-cell-inner {
    display: block;
    padding: @data-grid-checkbox-cell-inner__padding-top @data-grid-checkbox-cell-inner__padding-horizontal .9rem;
    text-align: center;

    > span {
        display: inline-block;
        font-style: @font-style__emphasis;
        padding: .6rem 0;
    }
}

//  Nested rows
.data-grid-row-parent {
    &._active {
        > td {
            .data-grid-checkbox-cell-inner {
                &:before {
                    content: @icon-caret-up__content;
                }
            }
        }
    }

    > td {
        .data-grid-checkbox-cell-inner {
            padding-left: (@data-grid-checkbox-cell-inner__padding-horizontal * .75) * 2 + @data-grid-row-parent-marker__size;
            position: relative;

            &:before {
                &:extend(.abs-icon all);
                content: @icon-caret-down__content;
                font-size: @data-grid-row-parent-marker__size;
                font-weight: @font-weight__bold;
                left: @data-grid-checkbox-cell-inner__padding-horizontal * .75;
                position: absolute;
                top: @data-grid-checkbox-cell-inner__padding-top + (@data-grid-row-parent-marker__size / 2);
            }
        }
    }
}

.data-grid-th {
    &._col-xs {
        width: 1%;
    }
}

//  Data Grid Info Panel
.data-grid-info-panel {
    box-shadow: 0 0 5px rgba(0, 0, 0, .5);
    margin: @data-grid-header-row__indent .1rem -(@data-grid-header-row__indent);

    .messages {
        overflow: hidden;

        .message {
            margin: @data-grid-th__padding-vertical;

            &:last-child {
                margin-bottom: @data-grid-th__padding-vertical;
            }
        }
    }
}

.data-grid-info-panel-actions {
    padding: @data-grid-th__padding-vertical;
    text-align: right;
}

//  Data Grid Inline Edit Validation
.data-grid-editable-row {
    @_field-error-triangle__width: 20px;
    @_field-error-triangle__height: 10px;
    @_field-error-input-triangle__width: 12px;

    .admin__field-control {
        position: relative;

        &._error {
            &:after {
                border-color: transparent @field-error-message__border-color transparent transparent;
                border-style: solid;
                border-width: 0 @_field-error-input-triangle__width @_field-error-input-triangle__width 0;
                content: '';
                position: absolute;
                right: 0;
                top: 0;
            }

            .admin__control-text {
                border-color: @field-error-message__border-color;
            }
        }

        &._focus {
            &:after {
                display: none;
            }
        }
    }

    .admin__field-error {
        bottom: 100%;
        box-shadow: @component__box-shadow__base;
        left: 0;
        margin: 0 auto 1.5rem;
        max-width: 32rem;
        position: absolute;
        right: 0;

        &:after,
        &:before {
            border-style: solid;
            content: '';
            left: 50%;
            position: absolute;
            top: 100%;
        }

        &:after {
            border-color: @field-error-message__background-color transparent transparent transparent;
            border-width: @_field-error-triangle__height (@_field-error-triangle__width / 2) 0 (@_field-error-triangle__width / 2);
            margin-left: -(@_field-error-triangle__width / 2);
            z-index: 1;
        }

        &:before {
            border-color: @field-error-message__border-color transparent transparent transparent;
            border-width: (@_field-error-triangle__width / 2 + 1) (@_field-error-triangle__width / 2 + 2) 0 (@_field-error-triangle__width / 2 + 2);
            margin-left: -((@_field-error-triangle__width / 2 + 2));
        }
    }
}

//  Data Grid Bulk Editing panel
.data-grid-bulk-edit-panel {
    .admin__field-label-vertical {
        display: block;
        font-size: 1.2rem;
        margin-bottom: .5rem;
        text-align: left;
    }
}

//  Data Grid Change Indicator
@data-grid-row-changed__icon: @icon-edit__content;
@data-grid-row-changed-tooltip__background: @color-white-fog2;

.data-grid-row-changed {
    cursor: default;
    display: block;
    opacity: .5;
    position: relative;
    width: 100%;
    z-index: 1;

    &:after {
        &:extend(.abs-icon all);
        content: @data-grid-row-changed__icon;
        display: inline-block;
    }

    .data-grid-row-changed-tooltip {
        background: @data-grid-row-changed-tooltip__background;
        border-radius: 1px;
        border: 1px solid @data-grid-row-changed-tooltip__background;
        bottom: 100%;
        box-shadow: 0 3px 9px 0 rgba(0, 0, 0, .3);
        display: none;
        font-weight: @font-weight__regular;
        line-height: @line-height__base;
        margin-bottom: 1.5rem;
        padding: 1rem;
        position: absolute;
        right: -1rem;
        text-transform: none;
        width: 27rem;
        word-break: normal;
        z-index: 2;
    }

    &._changed {
        opacity: 1;
        z-index: 3;

        &:hover {
            .data-grid-row-changed-tooltip {
                display: block;
            }

            &:before {
                background: @data-grid-row-changed-tooltip__background;
                border: 1px solid @data-grid-row-changed-tooltip__background;
                bottom: 100%;
                box-shadow: 4px 4px 3px -1px rgba(0, 0, 0, 0.15);
                content: '';
                display: block;
                height: 1.6rem;
                left: 50%;
                margin: 0 0 .7rem -.8rem;
                position: absolute;
                transform: rotate(45deg);
                width: 1.6rem;
                z-index: 3;

                .ie9 & {
                    display: none;
                }
            }
        }
    }
}
